package cn.tedu.di;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestDI {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext spring =
                new ClassPathXmlApplicationContext(
                        "spring-config.xml");
        //按照类名去获取对象--类加了@Component注解spring就会ioc进行new
        Student s = (Student) spring.getBean("student");
//        Teacher t1 = new Teacher();
//        t1.name = "张三";
//        s.setTeacher(t1);
//        System.out.println(s.getTeacher());
        Teacher t = (Teacher) spring.getBean("teacher");
        System.out.println(s);//Student{name='jack'}
        System.out.println(t);//Teacher{name='Tony'}
    }
}
